package sharedGameLogic.players;

import java.io.Serializable;


/**
 * The class Character describes a character in the game.
 * A character in this game has the same kind of attributes
 * as most RPG game character have; a name, strength, wisdom
 * etc.
 * 
 * @author Tobias
 *
 */

public final class Character implements Serializable, Cloneable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 9143562436609382017L;
	private String name;
	private BattleStatus battleStatus;
	
	private int strength;
	private int agility;
	private int skill;
	private int reflex;
	private int wisdom;
	private int intelligence;
	private int endurance;
	
	/**
	 * Constructor for Character class.
	 * 
	 * @param name - The characters name
	 * @param str - The characters strength
	 * @param agi - The characters agility
	 * @param ski - The characters skill
	 * @param ref - The characters reflexes
	 * @param wisd - The characters wisdom
	 * @param inte - The characters intelligence
	 * @param end - The characters endurance
	 */
	public Character(String name, int str, int agi, int ski,
					int ref, int wisd, int inte, int end){
		
		this.name = name;
		strength = str;
		agility = agi;
		skill = ski;
		reflex = ref;
		wisdom = wisd;
		intelligence = inte;
		endurance = end;
		
		setBasicBattleStatus();
	}
	
	/**
	 * Initiates the characters battle status.
	 * Health and energy set to max.
	 */
	public void setBasicBattleStatus(){
		int atStr = Math.round(strength*0.65F + skill*0.35F);
		int atSpe = Math.round(agility*0.8F + skill*0.1F + reflex*0.1F);
		int atPre = Math.round(skill*0.8F + reflex*0.2F);
		int dodge = Math.round(agility*0.45F + reflex*0.45F + skill*0.1F);
		int block = Math.round(strength*0.75F + skill*0.1F + reflex*0.15F);
		int mStr = Math.round(wisdom*0.85F + intelligence*0.15F);
		int mPre = Math.round(intelligence*0.85F + wisdom*0.15F);
		int hp = Math.round(endurance*0.6F + strength*0.4F);
		int ene = Math.round(wisdom*0.6F + endurance*0.3F + intelligence*0.1F);
		
		battleStatus = new BattleStatus(atStr, atSpe, atPre, dodge, 
										block, mStr, mPre, hp, ene);
	}
	
	/**
	 * 
	 * @return
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * 
	 * @return
	 */
	public BattleStatus getBattleStatus(){
		return battleStatus;
	}
	
	public void setBattleStatus(BattleStatus bs){
		battleStatus = bs;
	}
	
	@Override
	public Object clone(){
		Character character = new Character(name, 
											strength,
											agility,
											skill,
											reflex,
											wisdom,
											intelligence,
											endurance);
		character.setBattleStatus((BattleStatus)this.battleStatus.clone());
		return character;
	}
	
	public int getStrength(){
		return strength;
	}
	public int getAgility(){
		return agility;
	}
	public int getSkill(){
		return skill;
	}
	public int getReflex(){
		return reflex;
	}
	public int getWisdom(){
		return wisdom;
	}
	public int getIntelligence(){
		return intelligence;
	}
	public int getEndurance(){
		return endurance;
	}
}
